package Bean;

import tools.TimeTools;

import javax.persistence.*;
import java.sql.Timestamp;
import java.util.Objects;

@Entity
@Table(name = "userinfo", schema = "bookloansystem", catalog = "")
public class UserinfoEntity {
    private int id;
    private String username;
    private String password;
    private String name;
    private String phone;
    private Integer age;
    private Timestamp lastLoginTime;
    private Timestamp registeTime;

   public UserinfoEntity(){
       registeTime=new Timestamp(System.currentTimeMillis());
    }
    @Id
    @Column(name = "id")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Basic
    @Column(name = "username")
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @Basic
    @Column(name = "password")
    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @Basic
    @Column(name = "name")
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Basic
    @Column(name = "phone")
    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    @Basic
    @Column(name = "age")
    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    @Basic
    @Column(name = "Last_login_time")
    public Timestamp getLastLoginTime() {
        return lastLoginTime;
    }
    //增强型日期显示
    public String formatLastLoginTime() {
        return TimeTools.timeStamp2Date(lastLoginTime, null);
    }

    //使用当前时间自动生成时间戳
    public void setLastLoginTime() {
       setLastLoginTime(new Timestamp(System.currentTimeMillis()));
    }
    public void setLastLoginTime(Timestamp lastLoginTime) {
        this.lastLoginTime = lastLoginTime;
    }

    @Basic
    @Column(name = "registe_time")
    public Timestamp getRegisteTime() {
        return registeTime;
    }
    //增强型日期显示
    public String formatRegisteTime() {
        return TimeTools.timeStamp2Date(registeTime, null);
    }
    public void setRegisteTime(Timestamp registeTime) {
        this.registeTime = registeTime;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        UserinfoEntity that = (UserinfoEntity) o;
        return id == that.id &&
                Objects.equals(username, that.username) &&
                Objects.equals(password, that.password) &&
                Objects.equals(name, that.name) &&
                Objects.equals(phone, that.phone) &&
                Objects.equals(age, that.age) &&
                Objects.equals(lastLoginTime, that.lastLoginTime) &&
                Objects.equals(registeTime, that.registeTime);
    }

    @Override
    public int hashCode() {
        return Objects.hash(id, username, password, name, phone, age, lastLoginTime, registeTime);
    }


    //增强功能

    /**
     * 获取格式化的时间
     * @param format def-null--yyyy-mm-dd hh:mm:ss
     * @return
     */
    public String FormateRegisteTime(String format){
        return TimeTools.timeStamp2Date(registeTime, format);
    }    public String FormateRegisteTime(){
        return TimeTools.timeStamp2Date(registeTime, null);
    }
    /**
     * 获取格式化的时间
     * @param format def-null--yyyy-mm-dd hh:mm:ss
     * @return
     */
    public String FormatelastLoginTime(String format){
        return TimeTools.timeStamp2Date(lastLoginTime, format);
    }
    public String FormatelastLoginTime(){
        return TimeTools.timeStamp2Date(lastLoginTime, null);
    }


}
